﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcImprovedTest.Controllers
{
	using MvcImprovedTest.Models;

	[HandleError]
	public class HomeController : Controller
	{
		private Product GetTestProduct()
		{
			Product test = new Product() { ID = 1, Name = "My Product", Extra = new List<ProductExtra>() };
			test.Extra.Add(new ProductExtra() { ExtraInfo1 = "Info 1", ExtraInfo2 = "Info 2" });
			test.Extra.Add(new ProductExtra() { ExtraInfo1 = "Info 1b", ExtraInfo2 = "Info 2b" });

			return test;
		}

		public ActionResult Index()
		{
			return View(GetTestProduct());
		}

		public ActionResult IndexImproved()
		{
			return View(GetTestProduct());
		}

		public ActionResult IndexViewData()
		{
			DummyViewData[] testArray = new DummyViewData[] { new DummyViewData(){ Value1 = 1, Value2 = 2 }, new DummyViewData(){ Value1 = 3, Value2 = 4 }
					, new DummyViewData(){ Value1 = 5, Value2 = 6 } };

			//We can't pass in the array directly because there is no new() method for a typed array
			ViewData["TestArray"] = new List<DummyViewData>(testArray);

			return View(GetTestProduct());
		}
	}
}
